package com.yellowpage.bigdata.action;

import java.io.IOException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.yellowpage.white.common.Configuration;
import com.yellowpage.white.common.Constants;
import com.yellowpage.white.struts.BaseAction;
import com.yellowpage.white.struts.Module;
import com.yellowpage.white.struts.OperationType;
import com.yellowpage.white.util.Util4Java;

import com.yellowpage.bigdata.data.TmApponoffActiveMonth;
import com.yellowpage.bigdata.service.TmApponoffActiveMonthService;

public class TmApponoffActiveMonthAction extends BaseAction {

	public String RESULT_QUERY = "query";
	public String RESULT_ADD = "add";
	public String RESULT_EDIT = "edit";

	private Configuration configuration;

	public void setConfiguration(Configuration configuration) {
		this.configuration = configuration;
	}

	private List<TmApponoffActiveMonth> tmApponoffActiveMonthList = new ArrayList<TmApponoffActiveMonth>();
	private List<Map> resultList = new ArrayList<Map>();

	private TmApponoffActiveMonth tmApponoffActiveMonth;
	private TmApponoffActiveMonthService tmApponoffActiveMonthService;

	private String selectedId;
	private String[] selectedIds;
	private String message;

	private String query_tmApponoffActiveMonthId;
	private String query_createUser;
	private String query_etlTime;
	private String query_cnts;
	private String query_monthId_start;
	private String query_monthId_end;
	private String query_channelNo;
	private String query_note;
	private String query_version;

	public void prepare() {
		super.prepare();

		if (this.selectedId != null && !this.selectedId.equals("")) {
			this.tmApponoffActiveMonth = tmApponoffActiveMonthService
					.getTmApponoffActiveMonth(Long.parseLong(selectedId));
		}
	}

	public String queryByPage() {
		initPageRender();

		Map queryMap = new HashMap();
		queryMap.put("monthId_start", query_monthId_start);
		queryMap.put("monthId_end", query_monthId_end);
		queryMap.put("channelNo", query_channelNo);
		queryMap.put("version", query_version);

		resultList = tmApponoffActiveMonthService
				.queryTmApponoffActiveMonthByPage(queryMap, pageRender);

		setPageRenderToRequest();

		return RESULT_QUERY;
	}

	public String toAdd() {
		return RESULT_ADD;
	}

	public String save() {

		tmApponoffActiveMonthService
				.saveTmApponoffActiveMonth(tmApponoffActiveMonth);

		message = "新增成功!";
		return RESULT_ADD;
	}

	public void validateSave() {
		if (tmApponoffActiveMonth.getMonthId().length() == 0) {
			this.addActionError("** MonthId 不能为空 !");
		}
		if (tmApponoffActiveMonth.getChannelNo().length() == 0) {
			this.addActionError("** ChannelNo 不能为空 !");
		}
		if (tmApponoffActiveMonth.getNote().length() == 0) {
			this.addActionError("** Note 不能为空 !");
		}
		if (tmApponoffActiveMonth.getVersion().length() == 0) {
			this.addActionError("** Version 不能为空 !");
		}

		this.setValidatorResult("//TmApponoffActiveMonthAdd.jsp");
	}

	public String toEdit() {
		Long id = new Long(selectedId);

		tmApponoffActiveMonth = tmApponoffActiveMonthService
				.getTmApponoffActiveMonth(id);

		return RESULT_EDIT;
	}

	public String update() {

		tmApponoffActiveMonthService
				.updateTmApponoffActiveMonth(tmApponoffActiveMonth);

		message = "修改成功!";

		return RESULT_EDIT;
	}

	public void validateUpdate() {
		if (tmApponoffActiveMonth.getMonthId().length() == 0) {
			this.addActionError("** MonthId 不能为空 !");
		}
		if (tmApponoffActiveMonth.getChannelNo().length() == 0) {
			this.addActionError("** ChannelNo 不能为空 !");
		}
		if (tmApponoffActiveMonth.getNote().length() == 0) {
			this.addActionError("** Note 不能为空 !");
		}
		if (tmApponoffActiveMonth.getVersion().length() == 0) {
			this.addActionError("** Version 不能为空 !");
		}
		this.setValidatorResult("//TmApponoffActiveMonthUpdate.jsp");
	}

	public String delete() {
		List ids = new ArrayList();

		for (String id : selectedIds) {
			ids.add(Long.valueOf(id));
		}

		try {
			this.tmApponoffActiveMonthService.delete(ids);
		} catch (Exception e) {
			System.out.println("异常....");
			this.addActionError("** 可能含有子记录约束冲�?删除失败 !");
		}

		return queryByPage();
	}

	/**
	 * getters and setters
	 * 
	 * @return
	 */
	public void setTmApponoffActiveMonth(
			TmApponoffActiveMonth tmApponoffActiveMonth) {
		this.tmApponoffActiveMonth = tmApponoffActiveMonth;
	}

	public TmApponoffActiveMonth getTmApponoffActiveMonth() {
		return tmApponoffActiveMonth;
	}

	public void setTmApponoffActiveMonthService(
			TmApponoffActiveMonthService tmApponoffActiveMonthService) {
		this.tmApponoffActiveMonthService = tmApponoffActiveMonthService;
	}

	public List<TmApponoffActiveMonth> getTmApponoffActiveMonthList() {
		return tmApponoffActiveMonthList;
	}

	public void setTmApponoffActiveMonthList(
			List<TmApponoffActiveMonth> tmApponoffActiveMonthList) {
		this.tmApponoffActiveMonthList = tmApponoffActiveMonthList;
	}

	public String getSelectedId() {
		return selectedId;
	}

	public void setSelectedId(String selectedId) {
		this.selectedId = selectedId;
	}

	public String[] getSelectedIds() {
		return selectedIds;
	}

	public void setSelectedIds(String[] selectedIds) {
		this.selectedIds = selectedIds;
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public List<Map> getResultList() {
		return resultList;
	}

	public void setResultList(List<Map> resultList) {
		this.resultList = resultList;
	}

	public String getQuery_tmApponoffActiveMonthId() {
		return this.query_tmApponoffActiveMonthId;
	}

	public void setQuery_tmApponoffActiveMonthId(String tmApponoffActiveMonthId) {
		this.query_tmApponoffActiveMonthId = tmApponoffActiveMonthId;
	}

	public String getQuery_createUser() {
		return this.query_createUser;
	}

	public void setQuery_createUser(String createUser) {
		this.query_createUser = createUser;
	}

	public String getQuery_etlTime() {
		return this.query_etlTime;
	}

	public void setQuery_etlTime(String etlTime) {
		this.query_etlTime = etlTime;
	}

	public String getQuery_cnts() {
		return this.query_cnts;
	}

	public void setQuery_cnts(String cnts) {
		this.query_cnts = cnts;
	}

	public String getQuery_monthId_start() {
		return this.query_monthId_start;
	}

	public void setQuery_monthId_start(String query_monthId_start) {
		this.query_monthId_start = query_monthId_start;
	}

	public String getQuery_monthId_end() {
		return this.query_monthId_end;
	}

	public void setQuery_monthId_end(String query_monthId_end) {
		this.query_monthId_end = query_monthId_end;
	}

	public String getQuery_channelNo() {
		return this.query_channelNo;
	}

	public void setQuery_channelNo(String channelNo) {
		this.query_channelNo = channelNo;
	}

	public String getQuery_note() {
		return this.query_note;
	}

	public void setQuery_note(String note) {
		this.query_note = note;
	}

	public String getQuery_version() {
		return this.query_version;
	}

	public void setQuery_version(String version) {
		this.query_version = version;
	}

}
